package bz;

public class BaoZiPu extends Thread{
//    BaoZi bz = new BaoZi();
//
//    public BaoZiPu() {
//    }
//
//    public BaoZiPu(BaoZi bz,String name) {
//        super(name);
//        this.bz = bz;
//    }

    @Override
    public void run() {
        while(true){
            synchronized (BaoZi.class){
                while(BaoZi.num>=5) {
                    try {
                        BaoZi.class.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }

                BaoZi.num++;
                System.out.println(getName() + "做好了一个包子，剩余" + BaoZi.num+ "个");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                BaoZi.class.notifyAll();
            }
        }
    }
}

